<template>
  <a-modal
    :body-style="bodyStyle"
    :title="title"
    :width="width"
    :visible="visible"
    :confirm-loading="loading"
    :destroy-on-close="true"
    :ok-button-props="{ props: {disabled: disableSubmit} }"
    cancel-text="关闭"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="loading">
      <treeAndListTemplate
        ref="treeAndListUi"
        :page-url-data="pageUrlData"
        :select-type="selectType"
        @openTableMenuSelect="openTableMenuSelect"
      />
    </a-spin>
  </a-modal>
</template>
<script>
import { changeLoadGeneralModal, changeSelectReturnData, changeModelInitWidth } from '@/utils/hyopen'
import { changeSelectRowMergeParam } from '@/utils/hylist'
export default {
  name: 'TreeAndListModal',
  components: { treeAndListTemplate: () => import('./treeAndListUi.vue') },
  data() {
    return {
      globalData: {},
      triggerOpenParam: {},
      openParam: {},
      formModel: {},
      showTableTplKey: 'downTableTplList',
      bodyStyle: { padding: '0px' },
      dialogVisible: true,
      screenWidth: 0,
      buttonLoading: false,
      buttonDisabled: false,
      width: this.initWidth(),
      screenWidthFix: 1,
      title: '操作',
      modalVisible: false,
      loading: false,
      selectType: 'checkbox',
      // selectType: 'radio',
      btnItem: null,
      formItem: null,
      disableSubmit: false,
      selectedRows: null,
      selectionTreeRows: null,
      selectionTableRows: null,
      selectionReturnRows: [],
      visible: false,
      pageUrlData: { S_PAGE_ID: '', S_PAGE_VER: '' }
    }
  },
  computed: {
    isVisible: {
      get() {
        return this.dialogVisible
      },
      set() {
        this.close()
        this.reset()
      }
    }
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.width = this.initWidth()
      })()
    }
  },
  methods: {
    initWidth() {
      const thisObj = this
      changeModelInitWidth(thisObj)
    },
    showLoadGeneralModal(btnItem, refOpen, triggerOpenParam) {
      const thisObj = this
      if (btnItem.compTag === undefined) {
        if (refOpen.triggerReturn === undefined || refOpen.triggerReturn.length === 0) {
          thisObj.disableSubmit = true
        }
      }
      this.triggerOpenParam = triggerOpenParam
      this.openParam = triggerOpenParam.openParam
      changeLoadGeneralModal(thisObj, btnItem, refOpen, triggerOpenParam)
    },
    // openTableMenuSelect(selectedRows) {
    //   console.log('openTableMfffsdfsdfsdfsenuSelect.选中数据', selectedRows)
    //   this.selectedRows = selectedRows
    // },
    // openTreeSelectData(selectedRows) {
    //   console.log('openTreeSelectData.选中数据', selectedRows)
    //   this.selectedRows = selectedRows
    // },
    openTableMenuSelect(globalData) {
      console.log('openTableMenuSelect.', globalData)
      this.globalData = globalData
      // console.log(this.openParam,'newRow 222.', selectedRows)
      // const newRow = changeSelectRow(this, this.selectedRows)
      // console.log('newRow 222.', newRow)
    },
    handleCancel() {
      this.visible = false
    },
    handleOk() {
      const thisObj = this
      thisObj.loading = true
      console.log('thisObj.globalData',thisObj.showTableTplKey,'thisObj.globalData')
      if (thisObj.globalData[thisObj.showTableTplKey] !== undefined) {
        const returnGlobalData = thisObj.globalData[thisObj.showTableTplKey]
        const returnRows = changeSelectReturnData(thisObj, returnGlobalData)
        this.$emit('returnQuickSelectRows', returnRows, this.formItem)
      }
      thisObj.loading = false
      this.visible = false
      this.$emit('close')
    }
  }
}
</script>
